package com.jerry.constellation.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.jerry.constellation.Adapter.LuckyBaseAdapter;
import com.jerry.constellation.R;
import com.jerry.constellation.activity.LuckyDetailsActivity;
import com.jerry.constellation.bean.StarInfoBean;


import java.util.List;

public class Lucky_Fragment extends Fragment {

    private GridView lucky_gv;
    private List<StarInfoBean.StarinfoBean> mData;
    private LuckyBaseAdapter luckyBaseAdapter;

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.lucky_fragment, container, false);
        initView(view);
        initData();
        //设置监听
        setlisterner();
        return view;
    }

    private void setlisterner() {
        lucky_gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                StarInfoBean.StarinfoBean bean = mData.get(i);
                String name=bean.getName();
                Intent intent = new Intent(getContext(), LuckyDetailsActivity.class);
                intent.putExtra("name",name);
                startActivity(intent);
            }
        });
    }

    private void initData() {
        //获取数据源
        Bundle bundle = getArguments();
        StarInfoBean infobean = (StarInfoBean) bundle.getSerializable("info");
        mData=infobean.getStarinfo();
        //创建适配器对象

        luckyBaseAdapter = new LuckyBaseAdapter(getContext(), mData);
        //设置适配器
        lucky_gv.setAdapter(luckyBaseAdapter);
    }

    private void initView(View view) {
        lucky_gv = view.findViewById(R.id.lucky_Gv);

    }


}
